package com.tanhua.model.vo;

import com.tanhua.model.domain.UserInfo;
import com.tanhua.model.mongo.Movement;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.util.StringUtils;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author Xiao
 * @date 2021/10/26
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class MovementsVO implements Serializable {
    private String id; //动态id

    private Long userId; //用户id
    private String avatar; //头像
    private String nickname; //昵称
    private String gender; //性别 man woman
    private Integer age; //年龄
    private String[] tags; //标签

    private String textContent; //文字动态
    private String[] imageContent; //图片动态
    private String distance; //距离
    private String createDate; //发布时间 如: 10分钟前
    private Integer likeCount; //点赞数
    private Integer commentCount; //评论数
    private Integer loveCount; //喜欢数

    private Integer hasLiked; //是否点赞（1是，0否）
    private Integer hasLoved; //是否喜欢（1是，0否）

    //审核状态：1为待审核，2为自动审核通过，3为待人工审核，4为人工审核拒绝，5为人工审核通过，6为自动审核拒绝
    private String state = "0";

    public static MovementsVO init(UserInfo userInfo, Movement movement) {
        MovementsVO movementsVO = new MovementsVO();
        //设置动态数据
        BeanUtils.copyProperties(movement, movementsVO);
        movementsVO.setId(movement.getId().toHexString());
        movementsVO.setState(movement.getState().toString());
        //设置用户数据
        BeanUtils.copyProperties(userInfo, movementsVO);
        if (!StringUtils.isEmpty(userInfo.getTags())) {
            movementsVO.setTags(userInfo.getTags().split(","));
        }
        //图片列表
        movementsVO.setImageContent(movement.getMedias().toArray(new String[]{}));
        //距离
        movementsVO.setDistance("500米");
        Date date = new Date(movement.getCreated());
        movementsVO.setCreateDate(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(date));
        //设置是否点赞(后续处理)
        movementsVO.setHasLoved(0);
        movementsVO.setHasLiked(0);
        return movementsVO;
    }
}
